#include "SearchResultDialog.h"
#include "../../../model/proxy/FightProxy.h"
#include "../../../model/proxy/UserProxy.h"
#include "../../../model/proxy/DungeonsProxy.h"
#include "../../../model/vo/DataVO.h"
#include "../../../model/static/StaticRole.h"
#include "../../../model/static/StaticItem.h"
#include "../EquipIcon.h"

SearchResultDialog::SearchResultDialog()
:mEnergy(NULL),mExp(NULL),mCoin(NULL),
mDesc(NULL),itemIcon(NULL)
{
    
}

SearchResultDialog::~SearchResultDialog()
{
	CC_SAFE_RELEASE(mEnergy);
	CC_SAFE_RELEASE(mExp);
	CC_SAFE_RELEASE(mCoin);
	CC_SAFE_RELEASE(mDesc);
}

bool SearchResultDialog::onAssignCCBMemberVariable( CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mEnergy", CCLabelTTF *, this->mEnergy);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mExp", CCLabelTTF *, this->mExp);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mCoin", CCLabelTTF *, this->mCoin);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mDesc", CCLabelTTF *, this->mDesc);
    
	return NULL;
}

bool SearchResultDialog::init()
{
	ModelDialog::init();
	return true;
}

void SearchResultDialog::onEnter()
{
	ModelDialog::onEnter();
	refresh();
}

void SearchResultDialog::onExit()
{
	ModelDialog::onExit();
}

void SearchResultDialog::refresh()
{
    int dungeonsID = FightProxy::getSingletonPtr()->dungeons;
    int floorID = FightProxy::getSingletonPtr()->floor;
    int taskID = FightProxy::getSingletonPtr()->task;
    TaskStatic* taskData = StaticDungeons::getSingletonPtr()->getTaskInfo(dungeonsID, floorID, taskID);
    
	mEnergy->setString(fcs("-%d", taskData->energy));
	mExp->setString(fcs("%d", FightProxy::getSingletonPtr()->awardInfo.exp));
	mCoin->setString(fcs("%d", FightProxy::getSingletonPtr()->awardInfo.coin));

	std::vector<EquipInfo*>& equipageList = FightProxy::getSingletonPtr()->awardInfo.equipList;
	if (!equipageList.empty())
	{
		itemIcon = EquipIcon::create(this);
		itemIcon->setInfo(equipageList[0]->id);
		itemIcon->setPosition(ccp(99, 126));
		addChild(itemIcon);
        ItemStatic* itemStatic = StaticItem::getSingletonPtr()->getItemInfo(equipageList[0]->id);
        mDesc->setString(itemStatic->name);
	}
    else
    {
        mDesc->setString("");
    }
	
	
    
    
	//mDesc->setString(fcs("%d", userVO.strength));
}

void SearchResultDialog::touchScreen()
{
	close();
}
